<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
namespace core;
defined('BY_JYA') or exit('error');
class session {
	private $expire;
	public function __construct($expire){
		$this->expire=$expire;
	}
	public function open() {
		return true;
	}

	public function close() {
		return true;
	}
	public function read($sid){
		
		$row=pdo_getcolumn('core_session',array('id'=>$sid,'expire >'=>TIMESTAMP),IN);
		if($row) {
			return $row;
		}
		return '';
	}
	public function write($sid, $data) {
		global $_AR;
		if(defined('NOSESSION')){
			return true;
		}
		$row = array();
		$row[IN] = $data;
		$row['ip']= CLIENT_IP;
		$row['expire'] = TIMESTAMP + $this->expire;
		//$row['id'] = $sid;
		//pdo_insert('core_session',$row,true);
		$check=pdo_getcolumn('core_session',array('id'=>$sid),'id');
		if($check){
			pdo_update('core_session',$row,array('id'=>$sid));
		}else{
			$row['id'] = $sid;
			pdo_insert('core_session',$row,true);
		}
		return true;
	}
	public function destroy($sid) {
		pdo_update('core_session',array(IN=>''),array('id'=>$sid));
		return true;
	}
	public function gc($expire) {
		pdo_delete('core_session', array('expire <'=>TIMESTAMP));
		return true;
	}
}